package com.dmgn.serviceimpl;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dmgn.bean.Archives;
import com.dmgn.bean.Project;
import com.dmgn.dao.ProjectMapper;
import com.dmgn.service.IArchivesService;
import com.dmgn.util.Setting;

public class ProjectServiceImpl implements IArchivesService{
	
	private ApplicationContext context;
	private int pageItem = Setting.pageItem;
	
	ProjectMapper projectMapper;
	public ProjectServiceImpl(){
		context=new ClassPathXmlApplicationContext("applicationContext.xml");
		projectMapper = (ProjectMapper)context.getBean("ProjectMapper");	
	}
	
	@Override
	public List<Archives> findArchives(int pageNo, String queryStr,
			String labelIdStr, String employeenumber) {
		return projectMapper.selectProject((pageNo-1)*pageItem,pageItem,queryStr,labelIdStr,employeenumber);
	}

	@Override
	public boolean addArchives(Archives archives) {
		if(projectMapper.insertSelective((Project)archives) == 1)
			return true;
		else
			return false;
	}

	@Override
	public Integer getTotalNum(String queryStr, String labelIdStr, String employeenumber) {
		return projectMapper.getTotalNum(queryStr, labelIdStr, employeenumber)/pageItem+1;
	}
	
	@Override
	public boolean updateAuditStatus(String idStr, int auditStatus) {
		if(projectMapper.updateAuditStatus(idStr,auditStatus) != 0)
			return true;
		else
			return false;
	}
	
	@Override
	public boolean updateStatus(String idStr, int status) {
		if(projectMapper.updateStatus(idStr,status) != 0)
			return true;
		else
			return false;
	}

	@Override
	public boolean updateLabel(String idStr, String labelIdStr) {
		if(projectMapper.updateLabel(idStr,labelIdStr) != 0)
			return true;
		else
			return false;
	}

	@Override
	public Archives findSingleArchives(int id) {
		return projectMapper.selectByPrimaryKey(id);
	}

	@Override
	public boolean updateFile(String idStr, String file) {
		if(projectMapper.updateFile(idStr, file) != 0)
			return true;
		else
			return false;
	}
	
}
